﻿using System.Linq;
using TMV.Models.Input;
using TMV.Repositories;
using TMV.UnitOfWork;

namespace TMV.Services
{
    public interface IRoleService : IApplicationService<ApplicationRole>
    {
        ApplicationRole GetByName(string name);
        //IEnumerable<ApplicationRole> GetByUser(string userId);
    }

    public class RoleService : ApplicationService<ApplicationRole>, IRoleService
    {
        private IUnitOfWork unitOfWork;
        private IRoleRepository roleRepository;

        public RoleService(IUnitOfWork unitOfWork, IRoleRepository roleRepository)
            : base(unitOfWork, roleRepository)
        {
            this.unitOfWork = unitOfWork;
            this.roleRepository = roleRepository;
        }

        public ApplicationRole GetByName(string name)
        {
            return roleRepository.Get(x => x.Name == name).FirstOrDefault();
        }

        //public IEnumerable<ApplicationRole> GetByUser(string userId)
        //{
        //    return roleRepository.Get(r => r.Users.Any(u => u.UserId == userId));
        //}
    }
}